package com.ruoyi.carbon.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.carbon.domain.ScmPurchaseContractDetail;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.carbon.domain.ScmPurchaseContract;
import com.ruoyi.carbon.service.IScmPurchaseContractService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购合同Controller
 * 
 * @author ruoyi
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/carbon/purchaseContract")
public class ScmPurchaseContractController extends BaseController
{
    @Autowired
    private IScmPurchaseContractService scmPurchaseContractService;

    /**
     * 查询采购合同列表
     */
    @PreAuthorize("@ss.hasPermi('carbon:purchaseContract:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScmPurchaseContract scmPurchaseContract)
    {
        startPage();
        List<ScmPurchaseContract> list = scmPurchaseContractService.selectScmPurchaseContractList(scmPurchaseContract);
        return getDataTable(list);
    }

    /**
     * 导出采购合同列表
     */
    @PreAuthorize("@ss.hasPermi('carbon:purchaseContract:export')")
    @Log(title = "采购合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmPurchaseContract scmPurchaseContract)
    {
        List<ScmPurchaseContract> list = scmPurchaseContractService.selectScmPurchaseContractList(scmPurchaseContract);
        ExcelUtil<ScmPurchaseContract> util = new ExcelUtil<ScmPurchaseContract>(ScmPurchaseContract.class);
        util.exportExcel(response, list, "采购合同数据");
    }

    /**
     * 获取采购合同详细信息
     */
    @PreAuthorize("@ss.hasPermi('carbon:purchaseContract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scmPurchaseContractService.selectScmPurchaseContractById(id));
    }

    /**
     * 新增采购合同
     */
    @PreAuthorize("@ss.hasPermi('carbon:purchaseContract:add')")
    @Log(title = "采购合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmPurchaseContract scmPurchaseContract)
    {
        return toAjax(scmPurchaseContractService.insertScmPurchaseContract(scmPurchaseContract));
    }

    /**
     * 修改采购合同
     */
    @PreAuthorize("@ss.hasPermi('carbon:purchaseContract:edit')")
    @Log(title = "采购合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmPurchaseContract scmPurchaseContract)
    {
        scmPurchaseContract.setAuditTime(DateUtils.getNowDate());
        scmPurchaseContract.setAuditUser(getUsername());
        return toAjax(scmPurchaseContractService.updateScmPurchaseContract(scmPurchaseContract));
    }

    /**
     * 删除采购合同
     */
    @PreAuthorize("@ss.hasPermi('carbon:purchaseContract:remove')")
    @Log(title = "采购合同", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scmPurchaseContractService.deleteScmPurchaseContractByIds(ids));
    }
}
